package com.saunter.service;

import com.saunter.extendMapper.ThemeExtendMapper;
import com.saunter.model.Theme;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("ThemeService")
public class ThemeService {
    @Autowired
    ThemeExtendMapper themeExtendMapper;

    public Theme getTheme() {
        return themeExtendMapper.getOne();
    }

    public int setTheme(Theme new_theme) {
        if(null == new_theme.getId()){
            Theme db_theme = this.getTheme();
            if(null != db_theme && null != db_theme.getId()) {
                new_theme.setId(db_theme.getId());
                return themeExtendMapper.updateByPrimaryKeySelective(new_theme);
            }else {
                new_theme.setName("default_theme");
                return themeExtendMapper.insertSelective(new_theme);
            }
        }else {
            return 1;
        }
    }
}
